<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>事件冒泡</title>
</head>

<body>
    <div class="father" style="width: 600px;height: 600px;background-color: chocolate;">
        <div class="son" style="width: 300px;height: 300px;background-color: rgb(99, 139, 248);"></div>
    </div>

    <script>
        const father = document.querySelector('.father')
        const son = document.querySelector('.son')

        // 开启事件捕获 addEventListener (事件名, 函数, 是否开启事件捕获 默认关闭)
        document.addEventListener('click', function () {
            alert('我是爷爷')
        }, true)

        father.addEventListener('click', function () {
            alert('我是爸爸')
        })

        son.addEventListener('click', function (e) {
            alert('我是儿子')
            // 阻止冒泡
            e.stopPropagation()
        })
    </script>
</body>

</html>